<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    #app {
        width: 600px;
        margin: 0 auto;
    }

    .inpu {
        width: 200px;
        height: 30px;
    }

    .center {
        display: flex;
        justify-content: space-between;
    }

    .center1 {
        display: flex;
        justify-content: space-between;
    }
    h2{
        text-align: center;
    }
    #todolist{
        border: 1px solid black;
        border-radius: 20px;
    }
</style>

<body>
    <div id="app">
        <div class="top">
            <div class="center">
                <label for="title" style="font-size: 50px;">ToDoLis</label>
                <div style="margin-top: 10px;">
                    <input type="text" v-model="text" v-mykey="add" @keyup.enter="add" class="inpu" id="title"
                        placeholder="添加to do">
                    <input type="button" value="添加" @click="add">
                </div>

            </div>
        </div>

        <div class="content">
            <div class="center1">
                <div style="width: 50%;padding-right: 20px;">
                    <h2>
                        正在进行
                    </h2>
                    <!-- 正在进行的任务 -->
                    <ol id="todolist" class="demo-box">
                        <!-- 遍历 todolist 进行添加 -->
                        <li v-for="(item,index) in todolist" :key="index">
                            <input v-if="checked" @click="okAdd(index)" type="checkbox">
                            {{item}}
                            <a href="javascript:void(0)" @click="remove(index)" :key="index">删除</a>
                        </li>
                    </ol>
                </div>
                <div style="width: 50%;padding-right: 20px;">
                    <h2>
                        已经完成
                    </h2>
                    <!-- 已完成的任务 -->
                    <ol id="todolist" class="demo-box">
                        <!-- 遍历 newlist 进行添加 -->
                        <li v-for="(item,index) in newlist" :value="item" :key="index">
                            <!-- <input v-if="checked" type="checkbox"> -->
                            {{item}}
                            <a href="javascript:void(0)" @click="okremove(index)" :key="index">删除</a>
                        </li>
                    </ol>
                </div>

            </div>
        </div>
    </div>

</body>
<script src="./vue.min.js"></script>
<script>

    var vm = new Vue({
        el: "#app",
        data: {
            todolist: [],
            newlist: [],
            text: "",
            checked: true
        },
        methods: {
            add() { //未完成任务添加
                this.todolist.push(this.text)
                this.text = ""
            },
            remove(index) { //未完成任务移除
                this.todolist.splice(index, 1)
            },
            okAdd(index) { //已完成添加
                if (this.checked) {
                    //如果 tolist的单选框选中 就添加到 newList
                    this.newlist.push(this.todolist[index])
                    //删除 tolist的任务
                    this.todolist.splice(index, 1);
                }
            },
            okremove(index) { //已完成移除
                this.newlist.splice(index, 1)
            }
        },
        directives: {
            //键盘事件
            mykey: {
                inserted(el) {
                    if (el.keyCode === 13) {
                        this.add()
                    }

                }
            }
        }
    });
</script>

</html>